package com.kgcx.schedule.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.kgcx.common.bean.ReturnData;
import com.kgcx.schedule.model.OptionallyBook;
import com.kgcx.schedule.model.OptionallyNow;
import com.kgcx.schedule.model.SpeciallyBook;
import com.kgcx.schedule.model.SpeciallyNow;
import com.kgcx.schedule.service.ScheduleSettingsService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(tags = "派单参数配置接口")
@RestController
@RequestMapping(value = "/v1/schedule/settings")
public class ScheduleSettingsController extends SuperController {
    @Resource
    private ScheduleSettingsService scheduleSettingsService;

    @RequestMapping(value = "/getOptionallyBook", method = RequestMethod.GET)
    @ApiOperation(value = "查询预约用车派单参数", httpMethod = "GET", notes = "查询预约用车派单参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city_id", value = "城市ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class) //
    })
    public ReturnData<OptionallyBook> getOptionallyBook() {
        return new ReturnData<OptionallyBook>(
                scheduleSettingsService.getSetting($long("city_id"), OptionallyBook.class));
    }

    @RequestMapping(value = "/updateOptionallyBook", method = RequestMethod.POST)
    @ApiOperation(value = "修改预约用车派单参数", httpMethod = "POST", notes = "修改预约用车派单参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city_id", value = "城市ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class) //
    })
    public ReturnData<OptionallyBook> updateOptionallyBook(
            @ApiParam(name = "setting", value = "预约用车派单参数对象", required = true) @RequestBody OptionallyBook domain //
    ) {
        scheduleSettingsService.updateSetting($long("city_id"), domain);
        return new ReturnData<OptionallyBook>(domain);
    }

    @RequestMapping(value = "/getOptionallyNow", method = RequestMethod.GET)
    @ApiOperation(value = "查询立即用车派单参数", httpMethod = "GET", notes = "查询立即用车派单参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city_id", value = "城市ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class) //
    })
    public ReturnData<OptionallyNow> getOptionallyNow() {
        return new ReturnData<OptionallyNow>(scheduleSettingsService.getSetting($long("city_id"), OptionallyNow.class));
    }

    @RequestMapping(value = "/updateOptionallyNow", method = RequestMethod.POST)
    @ApiOperation(value = "修改立即用车派单参数", httpMethod = "POST", notes = "修改立即用车派单参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city_id", value = "城市ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class) //
    })
    public ReturnData<OptionallyNow> updateOptionallyNow(
            @ApiParam(name = "setting", value = "立即用车派单参数对象", required = true) @RequestBody OptionallyNow domain //
    ) {
        scheduleSettingsService.updateSetting($long("city_id"), domain);
        return new ReturnData<OptionallyNow>(domain);
    }

    @RequestMapping(value = "/getSpeciallyBook", method = RequestMethod.GET)
    @ApiOperation(value = "查询预约接机/站派单参数", httpMethod = "GET", notes = "查询预约接机/站派单参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city_id", value = "城市ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class) //
    })
    public ReturnData<SpeciallyBook> getSpeciallyBook() {
        return new ReturnData<SpeciallyBook>(scheduleSettingsService.getSetting($long("city_id"), SpeciallyBook.class));
    }

    @RequestMapping(value = "/updateSpeciallyBook", method = RequestMethod.POST)
    @ApiOperation(value = "修改预约接机/站派单参数", httpMethod = "POST", notes = "修改预约接机/站派单参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city_id", value = "城市ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class) //
    })
    public ReturnData<SpeciallyBook> updateSpeciallyBook(
            @ApiParam(name = "setting", value = "预约接机/站派单参数对象", required = true) @RequestBody SpeciallyBook domain //
    ) {
        scheduleSettingsService.updateSetting($long("city_id"), domain);
        return new ReturnData<SpeciallyBook>(domain);
    }

    @RequestMapping(value = "/getSpeciallyNow", method = RequestMethod.GET)
    @ApiOperation(value = "查询立即接机/站派单参数", httpMethod = "GET", notes = "查询立即接机/站派单参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city_id", value = "城市ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class) //
    })
    public ReturnData<SpeciallyNow> getSpeciallyNow() {
        return new ReturnData<SpeciallyNow>(scheduleSettingsService.getSetting($long("city_id"), SpeciallyNow.class));
    }

    @RequestMapping(value = "/updateSpeciallyNow", method = RequestMethod.POST)
    @ApiOperation(value = "修改立即接机/站派单参数", httpMethod = "POST", notes = "修改立即接机/站单参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city_id", value = "城市ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class) //
    })
    public ReturnData<SpeciallyNow> updateSpeciallyNow(
            @ApiParam(name = "setting", value = "立即接机/站单参数对象", required = true) @RequestBody SpeciallyNow domain //
    ) {
        scheduleSettingsService.updateSetting($long("city_id"), domain);
        return new ReturnData<SpeciallyNow>(domain);
    }

    @RequestMapping(value = "/reset", method = RequestMethod.POST)
    @ApiOperation(value = "重置所有派单参数为出厂值", httpMethod = "POST", notes = "重置派单参数为出厂值")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city_id", value = "城市ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class) //
    })
    public ReturnData<Object> reset() {
        scheduleSettingsService.resetSettings($long("city_id"));
        return new ReturnData<Object>();
    }
}
